package com;

import java.util.Arrays;

/*
 * @Author 罗俊
 * @date 2020/10/28 - 2:52 下午
 *
 */
public class QuickSort {
    public static void main(String[] args) {

        int array[] = {
                45, 12, 30, 25, 67, 52, 85
        };

        sort(1, array.length - 1, 0, array);

        System.out.println(Arrays.toString(array));
    }

    public static void sort(int left, int right, int middleIndex, int[] array) {

        for (int i = left; i < right; i++) {

            if (array[i] < array[middleIndex]) {
                int temp = array[i];
                array[i] = array[middleIndex];
                array[middleIndex] = temp;

                if (i - left > 1) {

                    sort(left + 1, i - 1, left, array);
                }

                if (right - i > 1) {

                    sort(i + 1, right, i , array);
                }

                break;
            }
        }

    }
}
